﻿using huqiang.UIComposite;
using huqiang.UIEvent;
using huqiang.UIModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class MenuPage:UIPage
{
    class View
    {
        public UserEvent Back;
        public UserEvent last;
        public UserEvent next;
        public PopMenu Menu;
    }
    View view;
    public override void Initial(Transform parent, object dat = null)
    {
        base.Initial(parent, dat);
        view = LoadUI<View>("baseUI", "menupage");//"baseUI"创建的bytes文件名,"page"为创建的页面名
        view.Back.Click = (o, e) =>
        {
            view.Menu.Enity.gameObject.SetActive(true);
            view.Menu.SetPosition(e.CanPosition);
        };
        InitialData();
    }
    void InitialData()
    {
        GetMenu(view.Menu.Root);
        view.Menu.Refresh();
    }
    public static void GetMenu(MenuContext menu)
    {
        MenuContext mc = new MenuContext();
        mc.Content =  mc.Key = "OpenFile";
        mc.SetParent(menu);

        mc = new MenuContext();
        mc.Content = mc.Key = "SaveFile";
        mc.SetParent(menu);
        GetTypeMenu(mc);

        mc = new MenuContext();
        mc.Content = mc.Key = "CreateProject";
        mc.SetParent(menu);

        mc = new MenuContext();
        mc.Content = mc.Key = "ExportToBytes";
        mc.SetParent(menu);
        GetTestMenu(mc);
    }
    static void GetTypeMenu(MenuContext menu)
    {
        MenuContext mc = new MenuContext();
        mc.Key = ".db";
        mc.Content = ".db";
        mc.SetParent(menu);

        mc = new MenuContext();
        mc.Key = ".dbx";
        mc.Content = ".dbx";
        mc.SetParent(menu);

        mc = new MenuContext();
        mc.Key = ".json";
        mc.Content = ".json";
        mc.SetParent(menu);

        GetTestMenu(mc);
    }
    static void GetTestMenu(MenuContext menu)
    {
        for(int i=0;i<8;i++)
        {
            MenuContext mc = new MenuContext();
            mc.Key = "Test"+i.ToString();
            mc.Content = "Test" + i.ToString();
            mc.SetParent(menu);
        }
    }
}
